000100******************************************************************
000200*PROGRAM : Zip inquiry                                           *
000300*AUTHOR  : Minh-Tuan Ta                                          *
000400*DATE    : 02/13/12                                              *
000500*ABSTRACT: Zip code inquiry.                                     *
000600******************************************************************
000700 IDENTIFICATION DIVISION.
000800 PROGRAM-ID. ZIP-I.
000900 ENVIRONMENT DIVISION.
001000     SELECT INFILE   ASSIGN TO "ZIPFILE.DAT"
001100                     ORGANIZATION    IS  INDEXED
001200                     ACCESS          IS  DYNAMIC
001300                     RECORD KEY      IS  IN-ZIP
001400                     ALTERNATE KEY   IS  IN-CITY WITH DUPLICATES
001500                     FILE STATUS     IS  WS-STAT.
001600 DATA DIVISION.
001700 FILE SECTION.
001800 FD  INFILE.
001900 01  IN-REC.
002000     03  IN-ZIP      PIC X(5).
002100     03  IN-CITY     PIC X(30).
002200     03  IN-STATE    PIC X(2).
002300     03  IN-COUNTY   PIC X(30).
002400 WORKING-STORAGE SECTION.
002500 01  WS-VARS.
002600     03  WS-DATE.
002700         05  WS-YEAR         PIC 99.
002800         05  WS-MONTH        PIC 99.
002900         05  WS-DAY          PIC 99.
003000     03  WS-ZIP              PIC X(5).
003100     03  WS-STAT             PIC X(2).
003200 01  OUT-REC.
003300     03  OUT-ZIP     PIC X(5)    VALUE SPACES.
003400     03  OUT-CITY    PIC X(30)   VALUE SPACES.
003500     03  OUT-STATE   PIC X(2)    VALUE SPACES.
003600     03  OUT-COUNTY  PIC X(30)   VALUE SPACES.
003700 SCREEN SECTION.
003800 01  ENTER-SCRN.
003900     03  BLANK SCREEN.
004000     03  MENU.
004100         05  LINE 1  COL 01  VALUE "ZIPB-INQNUM".
004200         05          COL 73  PIC 9(2) FROM WS-MONTH.
004300         05          COL 75  VALUE "/".
004400         05          COL 76  PIC 9(2) FROM WS-DAY.
004500         05          COL 78  VALUE "/".
004600         05          COL 79  PIC 9(2) FROM WS-YEAR.
004700         05  LINE 6  COL 34  VALUE "ZIP CODE SYSTEM".
004800         05  LINE 8  COL 37  VALUE "ZIP INQUIRY".
004900         05  LINE 10 COL 29  VALUE "ENTER ZIP".
005000         05          COL 39  PIC X(5) TO WS-ZIP AUTO.
005100         05  LINE 12 COL 29  VALUE "ZIP CODE".
005200         05          COL 39  PIC X(5)    FROM OUT-ZIP.
005300         05  LINE 13 COL 29  VALUE "CITY".
005400         05          COL 39  PIC X(30)   FROM OUT-CITY.
005500         05  LINE 14 COL 29  VALUE "COUNTY".
005600         05          COL 39  PIC X(30)   FROM OUT-COUNTY.
005700         05  LINE 15 COL 29  VALUE "STATE".
005800         05          COL 39  PIC X(2)    FROM OUT-STATE.
005900         05  LINE 17 COL 29  VALUE "ENTER ZIP OR X TO EXIT".
006000 PROCEDURE DIVISION.
006100 100-MAIN.
006200     ACCEPT WS-DATE FROM DATE
006300     OPEN INPUT INFILE
006400     DISPLAY ENTER-SCRN
006500     ACCEPT  ENTER-SCRN
006600     MOVE    WS-ZIP TO IN-ZIP
006700     PERFORM UNTIL WS-ZIP = 'X' OR 'x'
006800         START INFILE KEY = IN-ZIP
006900             INVALID KEY
007000                 MOVE "RECORD NOT FOUND" TO IN-CITY
007100                 MOVE SPACES             TO IN-STATE
007200                 MOVE SPACES             TO IN-COUNTY
007300         END-START
007400         READ INFILE NEXT RECORD
007500         END-READ
007600         MOVE IN-ZIP     TO OUT-ZIP
007700         MOVE IN-CITY    TO OUT-CITY
007800         MOVE IN-STATE   TO OUT-STATE
007900         MOVE IN-COUNTY   TO OUT-COUNTY
008000         DISPLAY ENTER-SCRN
008100         ACCEPT  ENTER-SCRN
008200         MOVE    WS-ZIP TO IN-ZIP
008300     END-PERFORM.
008400     CLOSE INFILE
008500     EXIT PROGRAM.
008600
